<?php
	require_once PATH_OBJECT.'dataObject.php';
	
class dataObject_menu extends dataObject
{
 /* @desc    Identifiant du bloc menu
     * @var     int
     */
    public $_MENU_ID = 0;
    
    /**
     * @desc    Libellé du menu
     * @var     varchar
     */
    public $_MENU_NOM = '';
    /**
     * @desc    url d'accès au menu (facultatif)
     * @var     varchar
     */
    public $_MENU_URL = '';

    /**
     * @desc    Identifiant du menu parent directement rattaché s'il existe.
     * @var     int
     */
    public $_MENU_PARENT_ID = '';

    /**
     * @desc   Niveau d'affichage dans l'arborescence de navigation
     * @var     int
     */
    public $_MENU_NIVEAU = 0;
    
    /**
     * @desc    libellé fonctionnalité affiché sur les formulaires (facultatif)
     * @var     varchar
     */
    public $_MENU_AFFICHE = '';
    /**
     * @desc    style css appliqué pour ce bloc/fonctionnalité sur la page menu
     * @var     varchar
     */
    public $_MENU_CSS = '';
    
    /**
     * @desc    code evenement associé a la fonctionnalité 
     * @var     varchar
     */
    public $_MENU_EVENT = '';
    
    /**
     * @desc   position d'affichage dans l'arborescence de navigation
     * @var     int
     */
    public $_MENU_POS = 0;
    
    
    const BLOC_SYNTHESE_ID = 3;
    const BLOC_EDITIONS_ID = 6;
    
    const FCT_SIN_DECLARATION_ID = 50;
    const FCT_SIN_COMPLEMENT_ID = 51;
    
	public function __construct( $iId=0 )
    {
       parent::__construct();
	
       if ( $iId != 0 )
       {/**modification du traitement pour partir du tableau gsmenu */
       	/*
            $sQuery = "SELECT   *   /*+ dataObject_menu::__construct 
                       FROM menu 
            		   WHERE menu_id = ".$iId;
            
            $aRows =  self::$_oConnexion->query($sQuery);
			$aRow = $aRows[0];*/
            $this->_MENU_ID            = $iId;
            $this->_MENU_NOM           = constant('_MENU_'.$iId);
            $this->_MENU_AFFICHE       = constant('_MENU_'.$iId);
            //$this->_MENU_NOM           = htmlentities($aRow["menu_nom"]);
            //$this->_MENU_URL           = (!empty($aRow["MENU_URL"])) ? $aRow["menu_url"] : '#'; 
            //$this->_MENU_PARENT_ID     = $aRow["menu_parent_id"];
            //$this->_MENU_NIVEAU        = $aRow["menu_niveau"];
            //$this->_MENU_AFFICHE       = htmlentities($aRow["menu_affiche"]);
            //$this->_MENU_CSS           = $aRow["menu_css"];
            //$this->_MENU_EVENT         = $aRow["menu_event"];
            //$this->_MENU_POS	       = $aRow["menu_pos"];
 
       }
       
    }
    /**
     * récupere la table menu selon le(s) criter(s) précisés ou pas 
	 */
    function menu_select( $sCritere = null )
    {
        $aRow = false;
    	$sQuery = "SELECT   *    
                   FROM menu 
            	   WHERE 1=1 
            	   {$sCritere}
            	    order by menu_niveau, menu_pos";
        $aRow =  self::$_oConnexion->query($sQuery);

        return $aRow;
    }
    
	public function menu_getPremierNiveau()
    {
        $aRow = false;
    	$sCritere = "and menu_niveau = 1";
        $aRow =  $this->menu_select ($sCritere);
        
        return $aRow;
    }
    
	public function menu_getListeParent()
    {
        $aRow = false;
    	$sCritere = " and menu_niveau <> 3";
        $aRow =  $this->menu_select ($sCritere);
        
        return $aRow;
    }
    
    
	public function menu_getSousMenu($idMenu=null)
    {
    	$aRow = false;
    	if($idMenu != null || $idMenu != "")
    	{
    		$sCritere = "and menu_parent_id = ".$idMenu;
        	$aRow =  $this->menu_select ($sCritere);
       
    	}
    	
        return $aRow;
    }
	
public function menu_insert()
    {
    	$sQuery = "INSERT INTO menu (
    			menu_nom, 
    			menu_url,
    			menu_parent_id,
    			menu_niveau,
    			menu_affiche,
    			menu_css,
    			menu_event,
    			menu_pos
    			) values (
    			".self::$_oConnexion->text($this->_MENU_NOM)
    			.",".self::$_oConnexion->text($this->_MENU_URL)
    			.",".$this->_MENU_PARENT_ID
    			.",".$this->_MENU_NIVEAU
    			.",".self::$_oConnexion->text($this->_MENU_AFFICHE)
    			.",".self::$_oConnexion->text($this->_MENU_CSS)
    			.",".self::$_oConnexion->text($this->_MENU_EVENT)
    			.",".$this->_MENU_POS
    			.")";
    
    	return self::$_oConnexion->execute($sQuery);
    }
    
    public function menu_update()
    {    	
    	$sQuery = "UPDATE menu SET 
    		 	menu_nom 		= ".self::$_oConnexion->text($this->_MENU_NOM) .",
	            menu_url 		= ".self::$_oConnexion->text($this->_MENU_URL).",
	            menu_parent_id 	=  $this->_MENU_PARENT_ID ,
	            menu_niveau 	=  $this->_MENU_NIVEAU ,    
	            menu_affiche 	= ".self::$_oConnexion->text($this->_MENU_AFFICHE).",
	            menu_css 		= ".self::$_oConnexion->text($this->_MENU_CSS) .",
	            menu_event 		= ".self::$_oConnexion->text($this->_MENU_EVENT).",
	            menu_pos 		=  $this->_MENU_POS   
	    		WHERE menu_id 	= ".$this->_MENU_ID;
    	
    	return self::$_oConnexion->execute($sQuery);;
    }
    
	public function menu_delete()
    { 	
	    $sQuery = "DELETE FROM menu WHERE menu_id 	= ".$this->_MENU_ID;
    	
    	return self::$_oConnexion->execute($sQuery);
    }
}
?>